﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using GPSCrowdSource.DataStructures;

namespace GPSCrowdSource.Algorithms {
  

  /// <summary>
  /// Simulates GPS data by allowing a user to add/construct bogus
  /// GPS behaviors
  /// </summary>
  public class GPSSimulator : GPSListDataSource {

    #region Constructor
    public GPSSimulator() { }
    #endregion

    #region Simulator methods

    /// <summary>
    /// Add a cluster of points centered about the given location have a maximum
    /// radius of "rad" at the specified hour of the day.
    /// </summary>
    /// <param name="day">The day of the year from 0 to 364</param>
    /// <param name="hour">Hour of the day from 0 to 23</param>
    /// <param name="lat">Lattiude in decimal degrees</param>
    /// <param name="lon">Longitude in degrees</param>
    /// <param name="rad">Radius in feet</param>
    /// <param name="cnt">The number of points to generate</param>
    public void AddCluster(float lat, float lon, float rad, int day, int hour, int cnt) {
      double r = (1.0d/GeoConstants.DEG2FT)*((double)rad);

      Random rnd = new Random((int)DateTime.UtcNow.Ticks);

      double min = .05d*r;

      for(int i=0;i<cnt;i++) {
        
        double rx =  (((double)rnd.Next(0,1000))/1000.0)*r;
        double ry =  (((double)rnd.Next(0,1000))/1000.0)*r;
                
        if(rx < min) rx = min;
        if(ry < min) ry = min;

        DateTime dt = new DateTime(DateTime.UtcNow.Year,1,1,0,0,0);
        dt = dt.Add(new TimeSpan(day,hour,0,0));
        
        Add(new GeoPosition(dt, (float)(lat + rx),(float)(lon + ry)));
        }

      }
    
    /// <summary>
    /// Creates a GPS data stream that simulates passengers traveling along the
    /// given path.
    /// </summary>
    /// <param name="graph">The path being traveled</param>
    /// <param name="start">The starting time</param>
    public IDataSource CreateRailSimulation(Route graph) {
      throw new NotImplementedException("Not Done");
      
      }
    
    #endregion

    }

  }


